﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ArrowControl : MonoBehaviour
{
    public Vector2 speed_direction;//速度方向
    public float speed;//速度
    public float live_time;

    private void Start()
    {
        if(speed_direction.x == 0 && speed_direction.y > 0)
        {
            this.transform.eulerAngles += new Vector3(0,0,90f);
        }
        if (speed_direction.x < 0 && speed_direction.y == 0)
        {
            this.transform.eulerAngles += new Vector3(0, 0, 180f);
        }
        if (speed_direction.x == 0 && speed_direction.y < 0)
        {
            this.transform.eulerAngles += new Vector3(0, 0, 270f);
        }
    }
    void Update()
    {
        //运动
        transform.position += new Vector3(speed_direction.x, speed_direction.y, 0) * speed * Time.deltaTime;

        //回收
        if(live_time > 0)
        {
            live_time -= Time.deltaTime;
        }
        else
        {
            this.gameObject.SetActive(false);
            Destroy(this.gameObject);
        }
    }

    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "enemy")
        {
            collision.gameObject.GetComponent<Enemy>().GetHit();
            this.gameObject.SetActive(false);
            Destroy(this.gameObject);
        }
    }
}
